<?php
require_once 'renderer_relation.php';

class renderer_relation_has_and_belongs_to_many extends renderer_relation
{
    
    public function searchRender($fObject)
    {
         $this->lead->viewer->fObject = $fObject;

         
        if($fObject->getConfig('render_as') == 'link')
        {
		    return 'nuller';
        }
        else 
        {
            DatatypeRenderer::getInstance()->stackOwner($fObject->getName());      
            $options = $fObject->getOptions();

            $this->lead->viewer->options = $options;
            
            $tpl = $this->lead->viewer->fetch("{$this->path}/{$this->folderName}/search_select.tpl");       
            DatatypeRenderer::getInstance()->unStackOwner();        
            return $tpl;
        }
        
        
        
    }

    public function viewRender($fObject)
    {
        $coll = $fObject->getValue();

        $this->lead->viewer->fObject = $fObject;
		$this->lead->viewer->fRenderer = $this;
        
        $items = array();
        foreach($coll as $item)
        {
            $items[] = $fObject->resolveTags($item, $fObject->getConfig('display'));
        }
        
        $this->lead->viewer->items = $items;
                        
        return $this->lead->viewer->fetch("{$this->path}/{$this->folderName}/view_list_all.tpl");       
        
        
        
    }
    
    
    public function editRender($fObject)
    {
        $this->lead->viewer->fObject = $fObject;
        
        $options = $fObject->getOptions();

        $selected = array();
        if($fObject->getOwner()->isFetched())       
            $selected = $fObject->getValue()->getKeys();

         
        if($fObject->getConfig('render_as') == 'link')
        {
      		$coll = $fObject->getValue();
	       	$this->lead->viewer->collection = $coll;
		    return $this->lead->viewer->fetch("{$this->path}/{$this->folderName}/link_to_relation.tpl");       
        }
        else 
        {
            $this->lead->viewer->selected = $selected;
            $this->lead->viewer->options = $options;
                           
            return $this->lead->viewer->fetch("{$this->path}/{$this->folderName}/edit_dropdown.tpl");       
            
        }
            

            
                        
    }
    
    
}